﻿using System;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
[CreateAssetMenu(fileName = "AnimationClipEvent",menuName ="创建动画事件")]
public class AnimationClipEvent : ScriptableObject
{
    public GameObject animationModel;
    public RuntimeAnimatorController animatorController;
    public List<AnimationClipOverride> clips = new List<AnimationClipOverride>();
    public List<AnimationEventData> eventDatas = new List<AnimationEventData>();




#if UNITY_EDITOR
    public List<string> functions = new List<string>();
    public Dictionary<string,Type[]> functionEditors = new Dictionary<string, Type[]>();
    public Dictionary<string, string[]> paramterEditors = new Dictionary<string, string[]>();
    private void OnEnable()
    {
        functions.Clear();
        functionEditors.Clear();
        paramterEditors.Clear();
        var defaultFunction = typeof(AnimationEventFunction);
        var defaultArray = new string[0];
        foreach (var function in defaultFunction.GetMembers( System.Reflection.BindingFlags.Instance| System.Reflection.BindingFlags.NonPublic| System.Reflection.BindingFlags.Public))
        {
            if (function.DeclaringType == defaultFunction)
            {
                var functionAttributes = function.GetCustomAttributes(typeof(FunctionAttribute), false);
                if (functionAttributes.Length == 0)
                    continue;

                var paramterAttributes = function.GetCustomAttributes(typeof(ParameterAttribute),false);
                functionEditors.Add(function.Name, (functionAttributes[0] as FunctionAttribute).types);
                paramterEditors.Add(function.Name, paramterAttributes.Length > 0 ? (paramterAttributes[0] as ParameterAttribute).names : defaultArray);
                functions.Add(function.Name);
            }
        }
    }
#endif
}


public class FunctionEditor
{
    public string functionName;
    public Type[] types;
}

